﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace NExt.Handler.Base.Default
{
    public class ChainedResponseStreamBuilder: IReponseStreamBuilder
    {
        private readonly IEnumerable<IReponseStreamBuilder> reponseStreamBuilders;

        public ChainedResponseStreamBuilder(params IReponseStreamBuilder[] reponseStreamBuilders)
        {
            this.reponseStreamBuilders = reponseStreamBuilders;
        }

        public Stream Build(System.Web.HttpContext context)
        {
            foreach (IReponseStreamBuilder reponseStreamBuilder in reponseStreamBuilders)
            {
                Stream stream = reponseStreamBuilder.Build(context);
                if (stream != null)
                    return stream;
            }

            return null;
        }
    }
}
